package dao;

import domain.Question;
import domain.QuestionExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface QuestionMapper {
    long countByExample(QuestionExample example);

    int deleteByExample(QuestionExample example);

    @Delete({
        "delete from question",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into question (id, content, ",
        "has_pic, pic_url, ",
        "answer, type)",
        "values (#{id,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, ",
        "#{hasPic,jdbcType=INTEGER}, #{picUrl,jdbcType=VARCHAR}, ",
        "#{answer,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER})"
    })
    int insert(Question record);

    int insertSelective(Question record);

    List<Question> selectByExample(QuestionExample example);

    @Select({
        "select",
        "id, content, has_pic, pic_url, answer, type",
        "from question",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("dao.QuestionMapper.BaseResultMap")
    Question selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") Question record, @Param("example") QuestionExample example);

    int updateByExample(@Param("record") Question record, @Param("example") QuestionExample example);

    int updateByPrimaryKeySelective(Question record);

    @Update({
        "update question",
        "set content = #{content,jdbcType=VARCHAR},",
          "has_pic = #{hasPic,jdbcType=INTEGER},",
          "pic_url = #{picUrl,jdbcType=VARCHAR},",
          "answer = #{answer,jdbcType=VARCHAR},",
          "type = #{type,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Question record);
}